package telco.provider.service;

import java.util.Vector;

import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Message;
import swa2012.telco.broker.beans.Provider;
import swa2012.telco.broker.beans.ReceiveMessageStatus;

import telco.provider.beans.ProviderRegistrationStatus;
import telco.provider.manager.BrokerManager;
import telco.provider.manager.ClientManager;
import telco.provider.manager.MessageManager;

public class ClientServiceImpl implements ClientService {

	/*
	 * ClientServiceImpl
	 */
	public ProviderRegistrationStatus registerClient(Client c) 
	{
		if(ClientManager.getInstance().addClient(c))
		{
			return ProviderRegistrationStatus.REGISTRATION_OK;
		}
		else
		{
			return ProviderRegistrationStatus.REGISTRATION_ALREADY_REGISTERED;
		}
	}

	public ProviderRegistrationStatus deregisterClient(Client c) 
	{
		if(ClientManager.getInstance().removeClient(c))
		{
			return ProviderRegistrationStatus.REGISTRATION_OK;
		}
		else
		{
			return ProviderRegistrationStatus.REGISTRATION_ALREADY_DEREGISTERED;
		}
	}
	
	public ReceiveMessageStatus receiveMessage(Message msg) {
		BrokerCallbackImpl rcv = new BrokerCallbackImpl();
		return rcv.receiveMessage(msg);
	}

	public Vector<Message> getMessagesForClient(Client c) {
		return MessageManager.getInstance().getMessagesForReceiver(c);
	}

	public Vector<Client> getAvailableClients() {
		return ClientManager.getInstance().getAvailableClients();
	}

	public Vector<Provider> getAvailableProviders() {
		return new Vector<Provider>(BrokerManager.getInstance().getProviders());
	}
}
